function Login() {
  var url = "/cgi-bin/database.cgi?";
  var usr = document.getElementById("usr").value;
  var ps = document.getElementById("ps0").value;
  if (usr == "") {
    alert("请输入账号");
    return;
  } else if (ps == "" && usr != "") {
    alert("请输入密码");
    return;
  }
  if (validateInput(usr) == false || validateInput(ps) == false) {
    alert("不许包含空白符");
    return;
  }
  url = url + "l" + usr + "l" + ps;

  xmlhttp = new XMLHttpRequest();
  xmlhttp.open("GET", url, true);
  xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      // 获取响应文本
      var out = xmlhttp.responseText;
      if (out == "0") {
        alert("账号不存在或密码错误！");
      } else if (out == "1") {
        alert("登录成功！");
        window.location.href = "http://125.216.248.13/test01.html";
      }
    }
  };
  xmlhttp.send();
}

function Regist() {
  window.location.href = "http://125.216.248.13/regist.html";
}

function Back() {
  window.location.href = "http://125.216.248.13/login.html";
}

function validateInput(input) {
  return !/\s/.test(input); // 如果字符串中包含任何空白字符，则返回 false
}

function SureRegist() {
  var url = "/cgi-bin/database.cgi?";
  var usr = document.getElementById("usr1").value;
  var ps1 = document.getElementById("ps1").value;
  var ps2 = document.getElementById("ps2").value;

  if (usr == "") {
    alert("请输入账号");
    return;
  } else if (ps1 == "" && ps2 != "") {
    alert("请输入密码");
    return;
  } else if (ps2 == "") {
    alert("请第二次输入密码");
    return;
  } else if (ps1 != ps2) {
    alert("两次输入的密码不相同，请重新输入");
    return;
  }
  if (validateInput(usr) == false || validateInput(ps1) == false) {
    alert("不许包含空白符");
    return;
  }
  if (ps1 == ps2) {
    url = url + "r" + usr + "r" + ps1; //读取r r为注册 对数据库的myuser表insert into

    xmlhttp = new XMLHttpRequest();
    xmlhttp.open("GET", url, true);
    xmlhttp.onreadystatechange = function () {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        // 获取响应文本
        var out = xmlhttp.responseText;
        alert(out);
      }
    };
    xmlhttp.send();
  }
}
